import  axios from 'axios'

const requerst = axios.create({
   baseURL:import.meta.env.VITE_APP_SERVER_URL, //请求的接口域名
   timeout: 3000,//请求超时时间
   headers:{},
})
//请求处理
requerst.interceptors.request.use(config=>{
    if(config.url!=='/api/login'){
      let token  = localStorage.getItem('token')
       config.headers['Authorization'] = "Bearer " + token
    }
    return config
  },
  error=>{
    return Promise.reject(error)
  }
)

//响应处理

requerst.interceptors.response.use(response =>{
  let data = response.data
  if(data.status_code == 200){
    console.log('响应拦截',data);
    
  }else if(data.status_code == 500) {
    console.log('响应拦截 错误',data);
  }
    return data
  },
  error=>{
    return Promise.reject(error)
  }
)

export default requerst